{
LANG : PASCAL
PROB : cfair
}

program CFAIR;
const
  fi = 'cfair.in';
  fo = 'cfair.out';
  max = 400;
var
  t : array[0..max, 0..max] of longint;
  p, ID, d : array[0..max] of longint;
  n, maximum : longint;

procedure inp;
var
  i, j : longint;
begin
  read(n);
  for i := 1 to n do
  begin
    read(p[i]);
    ID[i] := i;
  end;
  ID[0] := 0;
  p[0] := 0;
  fillchar(t, sizeof(t), 0);
  for i := 1 to n do
    for j := 1 to n do read(t[i, j]);
  for i := 0 to n do t[0, i] := t[1, i];
end;

procedure swap(i, j : longint);
var
  temp : longint;
begin
  temp := ID[i];
  ID[i] := ID[j];
  ID[j] := temp;
end;

procedure sort(l, r : longint);
var
  i, j, k : longint;
begin
  if l >= r then exit;
  i := l;
  j := r;
  k := p[ID[l+random(r-l+1)]];
  repeat
    while p[ID[i]] < k do inc(i);
    while p[ID[j]] > k do dec(j);
    if i <= j then
    begin
      swap(i, j);
      inc(i);
      dec(j);
    end;
  until i > j;
  sort(i, r); sort(l, j);
end;

procedure process;
var
  i, j : longint;
begin
  maximum := -1;
  d[0] := 0;
  for i := 1 to n do
    for j := 0 to i-1 do
      if (p[ID[j]] + t[ID[j], ID[i]] <= p[ID[i]]) and (d[i] < d[j] + 1) then
      begin
        d[i] := d[j] + 1;
        if maximum < d[i] then maximum := d[i];
      end;
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  inp;
  sort(1, n);
  process;
  writeln(maximum);
  close(output);
  close(input);
end.